home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / kernel / stkbd.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  13KB  |  512 lines

  1.  
  2. #if (CHIP == M68000)
  3. /*
  4.  * The ACIA driver for the Atari ST, both MDI and KBD
  5.  *
  6.  * Modified the original 1.1 code to support more
  7.  * function keys and provide a robust way of determing
  8.  * which keys are function keys. 
  9.  * Note: defining KEYBOARD as PC (in <minix/config.h>
  10.  *     will result in key definitions
  11.  *       that are the same as for Minix 1.1 with the
  12.  *       exception that <Shift><ClrHome> works and
  13.  *       <Insert> generates ESC [I
  14.  *                                    S.Poole 21.1.89 
  15.  */
  16. #include "kernel.h"
  17. #include <minix/com.h>
  18. #include <sgtty.h>
  19.  
  20. #include "staddr.h"
  21. #include "stacia.h"
  22.  
  23. #include "tty.h"
  24.  
  25. #define THRESHOLD                 20    /* # chars to accumulate before msg */
  26.  
  27. static void kbdkey();
  28. static int national();
  29. static void kbdkeypad();
  30. static void kbdarrow();
  31. static void kbdpf();
  32.  
  33. /*
  34.  * Translation from keyboard codes into internal (ASCII like) codes
  35.  * These tables represents a US keyboard, so MINIX.IMG as found on
  36.  * the MINIX-ST BOOT floppy works well in the US.
  37.  * The TOS program FIXKEYS.PRG is supplied to replace the keyboard
  38.  * tables compiled into MINIX.IMG on the BOOT floppy, by the proper
  39.  * national version of the keyboard tables used by TOS at the time
  40.  * of running FIXKEYS.PRG.
  41.  *
  42.  * Since these three tables are not fully sufficient to deal with
  43.  * all the differences, some special code is added in this driver
  44.  * to cope with the national combinations with the ALT key. See
  45.  * the routine national() below.
  46.  *
  47.  * Currently there are no provisions for non-ASCII characters.
  48.  * Only the problem of entering the ASCII character set from a
  49.  * variety of different keyboard layout is solved.
  50.  * Non-ASCII characters cause three kinds of problems:
  51.  *  - character codes above 127 loose their 8th bit in the TTY driver,
  52.  *    if not in RAW mode
  53.  *  - application programs do not know what to do with non-ASCII,
  54.  *    and certainly not with the character codes Atari did assign
  55.  *  - only ASCII characters can be displayed on the screen, since the
  56.  *    font tables used by MINIX-ST have only 128 entries.
  57.  */
  58.  
  59. #include "keymap.h"
  60.  
  61. /*
  62.  * Flag for keypad mode
  63.  * this can be set by code in stvdu.c
  64.  */
  65. #if (KEYBOARD == IBM_PC)
  66. PUBLIC int keypad = FALSE;
  67. #else
  68. PUBLIC int keypad = TRUE;
  69. #endif
  70. /*
  71.  * Flag for arrow key application mode
  72.  * this can be set by code in stvdu.c
  73.  */
  74. PUBLIC int app_mode = FALSE;
  75.  
  76. /* 
  77.  * Map function keys to an index into the 
  78.  * table of function key values 
  79.  */
  80. PRIVATE unsigned char f_keys[] = {
  81. /*00*/       0,   0,   0,   0,   0,   0,   0,   0,
  82. /*08*/       0,   0,   0,   0,   0,   0,   0,   0,
  83. /*10*/       0,   0,   0,   0,   0,   0,   0,   0,
  84. /*18*/       0,   0,   0,   0,   0,   0,   0,   0,
  85. /*20*/       0,   0,   0,   0,   0,   0,   0,   0,
  86. /*28*/       0,   0,   0,   0,   0,   0,   0,   0,
  87. /*30*/       0,   0,   0,   0,   0,   0,   0,   0,
  88. /*38*/       0,   0,   0,   1,   2,   3,   4,   5,
  89. /*40*/       6,   7,   8,   9,  10,   0,   0,  17,
  90. /*48*/      16,   0,  26,  13,   0,  15,  30,   0,
  91. /*50*/      14,   0,  18,   0,   1,   2,   3,   4,
  92. /*58*/       5,   6,   7,   8,   9,  10,   0,   0,
  93. /*60*/       0,  11,  12,  19,  20,  21,  22,  23,
  94. /*68*/      24,  25,  27,  28,  29,  31,  32,  33,
  95. /*70*/      34,  35,  36,   0,   0,   0,   0,   0,
  96. /*78*/       0,   0,   0,   0,   0,   0,   0,   0
  97. };
  98.  
  99. /*
  100.  * Numbering of the function keys, this scheme was chosen
  101.  * so that it easy to determine which function to call to actually
  102.  * generate the string.
  103.  *
  104.  * Note: the <Help> and <Undo> keys are considered to be function
  105.  *       keys 11 and 12.
  106.  *
  107.  * F-keys:    -----------------------------------------
  108.  *            | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10|
  109.  *            -----------------------------------------
  110.  *
  111.  * Arrow-Keys:    -------------
  112.  *                |  12 |  11 |
  113.  *                -------------
  114.  *                | 18| 16| 17|
  115.  *                -------------
  116.  *                | 13| 14| 15|
  117.  *                -------------
  118.  *
  119.  * Keypad:    -----------------
  120.  *            | 19| 20| 21| 22|
  121.  *            -----------------
  122.  *            | 23| 24| 25| 26|
  123.  *            -----------------
  124.  *            | 27| 28| 29| 30|
  125.  *            -----------------
  126.  *            | 31| 32| 33|   |
  127.  *            ------------- 36|
  128.  *            |   34  | 35|   |
  129.  *            -----------------
  130.  */     
  131.  
  132. /* 
  133.  * There is no problem with  expanding this struct to
  134.  * have a field for <Control> and <Alternate> (and combinations
  135.  * of them),  but who needs > 152 function keys? 
  136.  */
  137. struct fkey {
  138.     char norm, shift;
  139. };
  140.  
  141. PRIVATE struct fkey ftbl[] = {
  142. #if (KEYBOARD == IBM_PC)
  143.     /* 1  = F1      */ {'P',   0},
  144.     /* 2  = F2      */ {'Q',   0},
  145.     /* 3  = F3      */ {'R',   0},
  146.     /* 4  = F4      */ {'S',   0},
  147.     /* 5  = F5      */ {'T',   0},
  148.     /* 6  = F6      */ {'U',   0},
  149.     /* 7  = F7      */ {'V',   0},
  150.     /* 8  = F8      */ {'W',   0},
  151.     /* 9  = F9      */ {'X',   0},
  152.     /* 10 = F10     */ {'Y',   0},
  153.     /* 11 = Undo    */ {  0,   0},
  154.     /* 12 = Help    */ {  0,   0},
  155. #else
  156. /* 
  157.  * So that we can produce VT200 style function-key codes, 
  158.  * the values here are integer values that are converted
  159.  * to a string in kbdpf(). 
  160.  *
  161.  * The assignment of numbers to keys is rather chaotic,
  162.  * but at least all the VT200 keys are there.
  163.  */
  164.     /* ST key       */        /* VT200 key    */
  165.     /* 1  = F1      */ {  1,  21},    /* Find      F10    */
  166.     /* 2  = F2      */ {  2,  23},    /* Insert F11    */
  167.     /* 3  = F3      */ {  3,  24},    /* Remove F12    */
  168.     /* 4  = F4      */ {  4,  25},    /* Select F13    */
  169.     /* 5  = F5      */ {  5,  26},    /* Prev.  F14    */
  170.     /* 6  = F6      */ {  6,  31},    /* Next      F17    */
  171.     /* 7  = F7      */ { 17,  32},    /* F6      F18    */
  172.     /* 8  = F8      */ { 18,  33},    /* F7      F19    */
  173.     /* 9  = F9      */ { 19,  34},    /* F8      F20    */
  174.     /* 10 = F10     */ { 20,  35},    /* F9        */
  175.     /* 11 = Undo    */ { 36,  37},    /*        */
  176.     /* 12 = Help    */ { 28,  29},    /* Help      Do    */
  177. #endif
  178. /* 
  179.  * The following codes are more conventional 
  180.  */
  181.     /* 13 = Left    */ {'D',   0},
  182.     /* 14 = Down    */ {'B',   0},
  183.     /* 15 = Right   */ {'C',   0},
  184.     /* 16 = Up      */ {'A',   0},
  185.     /* 17 = ClrHome */ {'H', 'J'},
  186.     /* 18 = Insert  */ {'I',   0},
  187. /* 
  188.  * Keypad starts here 
  189.  */
  190.     /* 19 = (       */ {'P',   0},
  191.     /* 20 = )       */ {'Q',   0},
  192.     /* 21 = /       */ {'R',   0},
  193.     /* 22 = *       */ {'S',   0},
  194.     /* 23 = 7       */ {'w',   0},
  195.     /* 24 = 8       */ {'x',   0},
  196.     /* 25 = 9       */ {'y',   0},
  197.     /* 26 = -       */ {'m',   0},
  198.     /* 27 = 4       */ {'t',   0},
  199.     /* 28 = 5       */ {'u',   0},
  200.     /* 29 = 6       */ {'v',   0},
  201.     /* 30 = +       */ {'l',   0},
  202.     /* 31 = 1       */ {'q',   0},
  203.     /* 32 = 2       */ {'r',   0},
  204.     /* 33 = 3       */ {'s',   0},
  205.     /* 34 = 0       */ {'p',   0},
  206.     /* 35 = .       */ {'n',   0},
  207.     /* 36 = Enter   */ {'M',   0}
  208. };
  209.  
  210. PRIVATE message    kbdmes;        /* message used for console input chars */
  211. PRIVATE int    repeatkey;    /* character to repeat */
  212. PRIVATE int    repeattic;    /* time to next repeat */
  213.  
  214. /*===========================================================================*
  215.  *                kbdint                         *
  216.  *===========================================================================*/
  217. PUBLIC void kbdint()
  218. {
  219.   register code, make, k;
  220.   int s = lock();
  221.  
  222.   k = tty_buf_count(tty_driver_buf);
  223.   /*
  224.    * There may be multiple keys available. Read them all.
  225.    */
  226.   while (KBD->ac_cs & A_IRQ) {
  227.     code = KBD->ac_da;
  228. /*    printf("kbd: got %x\n", code & 0xFF); */
  229.     /*
  230.      * The ST's keyboard interrupts twice per key,
  231.      * once when depressed, once when released.
  232.      * Filter out the latter, ignoring all but
  233.      * the shift-type keys.
  234.          */
  235.     make = code & 0x80 ? 0 : 1;    /* 1=depressed, 0=released */
  236.     code &= 0x7F;
  237.     switch (code) {
  238.     case 0x2A:    /* shift key on left */
  239.         shift1 = make; continue;
  240.     case 0x36:    /* shift key on right */
  241.         shift2 = make; continue;
  242.     case 0x1D:    /* control */
  243.         control = make; continue;
  244.     case 0x38:    /* alt key */
  245.         alt = make; continue;
  246.     case 0x3A:    /* caps lock */
  247.         if (make) capslock ^= 1; continue;
  248.     }
  249.     if (make == 0) {
  250.         repeattic = 0;
  251.         continue;
  252.     }
  253.     repeatkey = code;
  254.     repeattic = 24;    /* delay: 24 * 16 msec == 0.4 sec */
  255.     kbdkey(code);
  256.   }
  257.   if (tty_buf_count(tty_driver_buf) < THRESHOLD) {
  258.     /* Don't send message.  Just accumulate.  Let clock do it. */
  259.     INT_CTL_ENABLE;
  260.     flush_flag++;
  261.   } else rs_flush();            /* send TTY task a message */
  262.   restore(s);
  263. }
  264.  
  265. /*==